<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<html>
  <head>
    <title>用户管理</title>
	<link rel="stylesheet" type="text/css" href="../../third/jquery-easyui-1.3.3/themes/default/easyui.css" >
	<link rel="stylesheet" type="text/css" href="../../third/jquery-easyui-1.3.3/themes/icon.css">
	<script type="text/javascript" src="../../third/jquery-easyui-1.3.3/jquery.min.js"></script>
	<script type="text/javascript" src="../../third/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../third/jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>


<script type="text/javascript">
		
		var url="";
		
		function searchUser() {         //搜索功能

			$('#dg').datagrid('load', {
				id : $('#s_id').val(),
				name : $('#s_name').val(),
				pid : $('#s_pid').val(),
				url : $('#s_url').val(),
				
			});
		}
		
		function deleteUser() {  //删除功能
			var selectedRows = $("#dg").datagrid('getSelections');
			if (selectedRows.length == 0) {
				$.messager.alert("系统提示", "请选择一行需要删除的数据!");
				return;
			}
			var strIds = [];
			for (i = 0; i < selectedRows.length; i++) {
				strIds.push(selectedRows[i].id);
			}
			var ids = strIds.join(",");
		//	$.messager.alert("系统提示", ids);
			$.messager.confirm("系统提示", "您确认要删除这<font color=red>"
					+ selectedRows.length + "</font>条数据吗?", function(r) {
				if (r) {
					$.post("../../menuDelete", {
						delIds : ids
					}, function(result) {
						if (result.success) {
							$.messager.alert("系统提示", "您已经成功删除<font color=red>"
									+ result.delNums + "</font>条数据！");
							$("#dg").datagrid("reload");
						} else {
							$.messager.alert("系统提示", result.errorMsg);
						}
					}, "json");
				}
			});
		}
		
		//打开添加对话框
		function openUserAddDialog() {   
			$("#dlg").dialog("open").dialog("setTitle","添加菜单信息");
			url="../../menuSave";
		}
		
		//保存
		function saveUser(){  
			$("#fm").form("submit",{
				url:url,
				onSubmit:function(){
					if($('#pid').combobox("getValue")==""){
						$.messager.alert("系统提示","请选择上一级的菜单");
						return false;
					}
					return $(this).form("validate"); //必填项
				},
				success:function(result){
					if(result.errorMsg){
						$.messager.alert("系统提示",result.errorMsg);
						return;
					}else{
						$.messager.alert("系统提示","保存成功");
						resetValue();
						$("#dlg").dialog("close");
						$("#dg").datagrid("reload");
					}
				}
			});
		}
		
		function openUserModifyDialog(){   //修改
			var selectedRows=$("#dg").datagrid('getSelections');
			if(selectedRows.length!=1){
				$.messager.alert("系统提示","请选择一条要编辑的数据！");
				return;
			}
			var row=selectedRows[0];
			$("#dlg").dialog("open").dialog("setTitle","编辑菜单信息");
			$("#fm").form("load",row);
			url="../../menuModify?id="+row.id;
		}
		
		function resetValue(){
			$("#id").val("");
			$("#name").val("");
			$("#pid").combobox("setValue","");
			$("#url").val("");
		}
		
		function closeUserDialog(){  //关闭对话框
			$("#dlg").dialog("close");
			resetValue();
		}
	</script>
	</head>
	<body>
		<table id="dg"  title="菜单信息" class="easyui-datagrid" fitColumns="true"
		 pagination="true" rownumbers="true" url="../../userList" fit="true" toolbar="#tb">
			<thead>
				<tr>
					<!-- 字段名称要对应 -->
					<th field="cb" checkbox="true"></th>
					<th field="id" width="50" align="center">编号</th>
					<th field="user_id" width="100" align="center">工号</th>
					<th field="fullname" width="100" align="center">姓名</th>
				</tr>
			</thead>
		</table>
	
		<div id="tb">
				<div>
						<a href="javascript:openUserAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
						<a href="javascript:openUserModifyDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">修改</a>
						<a href="javascript:deleteUser()" class="easyui-linkbutton" iconCls="icon-add" plain="true">删除</a>
				</div>
				<div>
						&nbsp;工号:&nbsp;<input type="text" id="s_user_id"  name="s_user_id" size="10"/>
						&nbsp;姓名:&nbsp;<input type="text" id="s_fullname" name="s_fullname" size="10"/>												
						
						<a href="javascript:searchUser()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
				</div>
		</div>
	
		<div id="dlg" class="easyui-dialog" style="width: 570px;height: 350px;padding: 10px 20px ; z-index:5555"
		 closed="true" buttons="#dlg-buttons" >
			<form id="fm" method="post">
				<table cellspacing="5px;">
					<tr>
						<td>工号：</td>
						<td><input type="text" name="user_id" id="user_id" class="easyui-validatebox" required="true"/></td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td>姓名：</td>
						<td><input type="text" name="fullname" id="fullname" class="easyui-validatebox" required="true"/></td>
					</tr>					
					<tr>
					<td>密码：</td>
						<td><input type="text" name="pwd" id="pwd" class="easyui-validatebox" required="true"/></td>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
					<td>所属角色：</td>
						<td><input class="easyui-combobox" id="pid" name="pid"  data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'name',url:'../../GetMenuPidList'"/></td>
					</tr>
				</table>
			</form>
		</div>
		
		<div id="dlg-buttons">
			<a href="javascript:saveUser()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
			<a href="javascript:closeUserDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
		</div>
	</body>
</html>